#include "Blocks/JackOLanternBlock.h"
#include "Components/ComponentMiner.h"
#include "Components/ComponentCreature.h"
#include "Components/ComponentCreatureModel.h"

namespace PocketSurvival
{
    int32_t JackOLanternBlock::getIndex()
    {
        return Index();
    }
    const std::string &JackOLanternBlock::getBlockName()
    {
        static std::string blockName = "JackOLanternBlock";
        return blockName;
    }

    const std::vector<BoundingBox> &JackOLanternBlock::getCustomCollisionBoxes(int32_t value)
    {
		return BlockConstans::jackOLanternCollisionBoxes;
    }

    BlockPlacementData JackOLanternBlock::getPlacementValue(ComponentMiner *componentMiner, int32_t value, const TerrainRaycastResult &raycastResult)
    {
		Vector3 forward = componentMiner->componentCreature->componentCreatureModel->getEyeRotation().toMatrix().getForward();
		float numBuff[4] = {
			Vector3::Dot(forward, FastVector3::UnitZ),
			Vector3::Dot(forward, FastVector3::UnitX),
			Vector3::Dot(forward, FastVector3::DecUnitZ),
			Vector3::Dot(forward, FastVector3::DecUnitX)
		};
		uint32_t targetIndex = MathUtils::MaxIndex<float>(numBuff, 4);
		int32_t rotation = 0;
		switch (targetIndex)
		{
		case 0:
			rotation = 0;
			break;
		case 1:
			rotation = 1;
			break;
		case 2:
			rotation = 2;
			break;
		case 3:
			rotation = 3;
			break;
		}
		BlockPlacementData result;
		result.value = Terrain::ReplaceData(Index(), rotation);
		result.cellFace = raycastResult.cellFace;
		return result;
    }

} // namespace PocketSurvival

